/**********************************************************

     文件名称: del_com.c

     项目功能: 删除商品信息 

     作者: 佳奇

     邮箱: 1374804492@qq.com 

     创建时间: Fri 26 Aug 2022 10:09:24 PM CST

**********************************************************/


#include <stdio.h>
#include <stdlib.h>
#include "sup_mgr.h"


//	查询商品信息 找到返回商品节点指针 未找到 返回 NULL
com_list* q_com(com_list* demo, int id)
{
	demo = demo->next;

	while(demo != NULL && demo->data->barcode != id)	demo = demo->next;

	if(demo == NULL)	return NULL;

	return demo;
}


//	通过条码删除商品信息
void del_com(com_list* demo)
{
	int com_id;
	com_list* s1 = demo, *s2;

	system("clear");
	printf("\n********删除商品信息模式********\n");

	while(1)
	{
		printf("\n请输入您要删除的商品条码(编号):");
		while(!geshipanduan(scanf("%d", &com_id)));
		c_buffer();

		while(demo->next != NULL && demo->next->data->barcode != com_id)	demo = demo->next;

		if(demo->next == NULL)
		{
			printf("\n未找到此件商品!\n");
			printf("是否继续进行删除操作(y/n):");
			
			if(getchar() == 'y')
			{	
				system("clear");
				demo = s1;
				continue;
			}
			else return;
		}

		printf("商品编号 %d 的信息如下:\n", com_id);

		printf("商品条码:%d", demo->next->data->barcode);
		printf("\n商品名称:%s", demo->next->data->com_name);
		printf("\n商品单价:%d", demo->next->data->unit);
		printf("\n商品厂家:%s", demo->next->data->manu);
		printf("\n商品数量:%d", demo->next->data->num);
		printf("\n商品余量:%d", demo->next->data->allow);

		s2 = demo->next;
		demo->next = s2->next;
		free(s2->data);
		free(s2);

		printf("\n删除完成!\n");
		printf("是否继续进行删除操作(y/n):");

		if(getchar() == 'y')
		{
			system("clear");
			demo = s1;
			continue;
		}
		else break;
	}

	c_buffer();
}


